<?php
/**
 # com_jvframwork - JV Framework
 # @version		1.5.x
 # ------------------------------------------------------------------------
 # author    Open Source Code Solutions Co
 # copyright Copyright (C) 2011 joomlavi.com. All Rights Reserved.
 # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL or later.
 # Websites: http://www.joomlavi.com
 # Technical Support:  http://www.joomlavi.com/my-tickets.html
-------------------------------------------------------------------------*/

// Check to ensure this file is within the rest of the framework
defined('JPATH_BASE') or die();

/**
 * Renders a list element
 *
 * @package 	Joomla.Framework
 * @subpackage		Parameter
 * @since		1.5
 */

class JElementColorlist extends JElement
{
	/**
	* Element type
	*
	* @access	protected
	* @var		string
	*/
	var	$_name = 'Colorlist';
    var $_activetheme = '';

	function fetchElement($name, $value, &$node, $control_name)
	{
		$class = ( $node->attributes('class') ? 'class="'.$node->attributes('class').'"' : 'class="inputbox"' );
        
        if(JFolder::exists(JPATH_ROOT.DS.'templates'.DS.'jv-framework'.DS.'themes'.DS.$this->getActiveTheme()->theme.DS.'css'.DS.'colors'.DS))
        $files = JFolder::files(JPATH_ROOT.DS.'templates'.DS.'jv-framework'.DS.'themes'.DS.$this->getActiveTheme()->theme.DS.'css'.DS.'colors'.DS,'css');
        
		$options = array ();
        if(isset($files) && count($files))
		foreach ($files as $option)
		{
			$val	= str_replace('.css','',$option);
			$text	= $val;
			$options[] = JHTML::_('select.option', $val, JText::_($text));
		}
        
		return JHTML::_('select.genericlist',  $options, ''.$control_name.'['.$name.']', $class, 'value', 'text', $value, $control_name.$name);
	}
    
    /**
     * Parameter 
     * 
     * @access public
     * @return void
     */
    function getActiveTheme() {
        if($this->_activetheme == null){
            $cids = JRequest::getVar ( 'cid', array (0 ), 'method', 'array');  
            
            if(preg_match('/[a-zA-Z]/',$cids[0])){
                $this->_activetheme = $cids[0];
            } else {
                $data =& JFactory::getDBO();        
                $data->setQuery('SELECT id, theme FROM #__jv_themes WHERE id='.$cids[0]); 
                $resulf = $data->loadObject();
                $resulf->theme = current(explode('|', $resulf->theme));
                
                $this->_activetheme = $resulf;   
            }
        }
        
        return $this->_activetheme;
    }
}
